<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${package.Mapper}.${cfg.moduleName}.${table.mapperName}">
    <#if enableCache>
        <!-- 开启二级缓存 -->
        <cache type="org.mybatis.caches.ehcache.LoggingEhcache"/>
    </#if>

    <sql id="baseSql">
        select t1.*
        from ${table.name} t1
        <where>
            <if test="query.keyword != null and query.keyword != '' ">
                and t1.id like concat('%', ${r"#{query.keyword}"}, '%')
            </if>
            <if test="query.beginTime != null and query.beginTime != '' ">
                <![CDATA[ and t1.create_time >= ${r"#{query.beginTime}"} ]]>
            </if>
            <if test="query.endTime != null and query.endTime != '' ">
                <![CDATA[ and t1.create_time <= ${r"#{query.endTime}"} ]]>
            </if>
        </where>
        order by t1.id desc
    </sql>

    <!--导出查询分页数据表格-->
    <select id="selectMySqlPage" resultType="${cfg.basePath}.domain.${cfg.moduleName}.${entity}">
        <include refid="baseSql"></include>
    </select>

    <!--导出Excel表格-->
    <select id="selectExportExcelData" resultType="${cfg.basePath}.domain.${cfg.moduleName}.${entity}">
        select t1.*
        from ${table.name} t1
        <if test="list != null and list.size() > 0">
            WHERE t1.id in
            <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
                ${r"#{item}"}
            </foreach>
        </if>
        order by t1.id desc
    </select>
</mapper>